import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/common/app_spaces.dart';
import 'package:finance_app/src/entities/bank_detail_record_item_entity.dart';
import 'package:finance_app/src/entities/bank_reconciliation_record_entity.dart';
import 'package:finance_app/src/utils/date_time_utils.dart';
import 'package:finance_app/src/widgets/bottom_sheet/default_bottom_sheet.dart';
import 'package:finance_app/src/widgets/button/normal_button.dart';
import 'package:finance_app/src/widgets/list_item/reconcile_top_list_item.dart';
import 'package:finance_app/src/widgets/select/reconcile_radio.dart';
import 'package:flutter/material.dart';

showBankMatchTransactionBottomSheet(
  BuildContext context,
  BankReconciliationRecordEntity bank,
  List<BankDetailRecordItemEntity> dataList,
  VoidCallback onUnmatch,
) =>
    showDefaultBottomSheet(
      context,
      title: S.current.matched_transaction,
      child: BankMatchTransactionWidget(
        bank: bank,
        dataList: dataList,
        onUnmatch: onUnmatch,
      ),
      isScrollControlled: true,
    );

class BankMatchTransactionWidget extends StatelessWidget {
  final BankReconciliationRecordEntity bank;
  final List<BankDetailRecordItemEntity> dataList;
  final VoidCallback onUnmatch;

  const BankMatchTransactionWidget(
      {Key key, this.bank, this.dataList, this.onUnmatch})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        AppSpaces.h30,
        AppSpaces.grayH05,
        ReconcileTopListItem(
          onTap: () {},
          name: bank.bankTransactionName,
          code: bank.bankTransactionNumber,
          datetime: DateTimeUtils.formatDateTimeString(bank.createdAt, true),
          status: null,
          amount: bank.total,
        ),
        Container(
          constraints: BoxConstraints(
            maxHeight: getDp(250),
          ),
          child: ListView.builder(
            shrinkWrap: true,
            itemBuilder: _buildItems,
            itemCount: dataList.length,
          ),
        ),
        AppSpaces.h30,
        NormalButton(
          title: S.current.unmatch,
          onTap: onUnmatch,
        ),
      ],
    );
  }

  Widget _buildItems(BuildContext context, int index) {
    final value = dataList[index];
    return ReconcileCheckBox(
      isSelect: true,
      isEnable: false,
      name: value.name,
      type: value.flowType,
      code: value.account.accountNumber,
      datetime: DateTimeUtils.formatDateTimeString(value.issuedAt, true),
      amount: value.total,
    );
  }
}
